home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / DropShadowWithPath / DropShadowWithPath.cs next >
Encoding:
Text File  |  2001-01-15  |  1.6 KB  |  49 lines

  1. //-------------------------------------------------
  2. // DropShadowWithPath.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class DropShadowWithPath: FontMenuForm
  10. {
  11.      const int iOffset = 10;   // Approximately 1/10 inch (exactly on printer)
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new DropShadowWithPath());
  16.      }
  17.      public DropShadowWithPath()
  18.      {
  19.           Text = "Drop Shadow with Path";
  20.           Width *= 2;
  21.           strText = "Shadow";
  22.           font = new Font("Times New Roman", 108);
  23.      }
  24.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  25.      {
  26.           GraphicsPath path = new GraphicsPath();
  27.           float fFontSize = PointsToPageUnits(grfx, font);
  28.                
  29.                // Get coordinates for a centered string.
  30.  
  31.           SizeF sizef = grfx.MeasureString(strText, font);
  32.           PointF ptf = new PointF((cx - sizef.Width) / 2, 
  33.                                   (cy - sizef.Height) / 2);
  34.                
  35.                // Add the text to the path.
  36.  
  37.           path.AddString(strText, font.FontFamily, (int) font.Style,
  38.                          fFontSize, ptf, new StringFormat());
  39.  
  40.                // Clear, fill, translate, fill, and draw.
  41.  
  42.           grfx.Clear(Color.White);
  43.           grfx.FillPath(Brushes.Black, path);
  44.           path.Transform(new Matrix(1, 0, 0, 1, -10, -10));
  45.           grfx.FillPath(Brushes.White, path);
  46.           grfx.DrawPath(Pens.Black, path);
  47.      }
  48. }
  49.